<?php

require_once '../application/controllers/Super_Controller.php';

class AddCommentController extends Super_Controller {

    public function indexAction() {
        Zend_Layout::getMvcInstance()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(TRUE);
        $data = $this->getRequest()->getParams();
        $PM = new Application_Model_Pages();
        $page_url = $PM->getPageUrl($data['page_id']);
        if (!empty($page_url)) {
            $data = $this->getRequest()->getParams();
            if ($data['captcha'] == ($_SESSION['captcha_keystring'] + 1)) {
                $COMM = new Application_Model_Comments();
                if ($COMM->addComment($data['page_id'], $data['name'], $data['comment'])) {
                    @mail('gubarevm@mail.ru', 'DEVELOPMENTS-BLOG::New comment', "http://" . $_SERVER['SERVER_NAME'] . '/admin/comments/index/pages/' . $data['page_id'] . "\n" . $data['comment']);
                }
                $this->_redirect($page_url);
            } else {
                Application_Model_MessageBox::setMessage('Не верно введены символы!');
                $this->_redirect($page_url . '?' . http_build_query(array(
                            'comment' => strip_tags($_POST['comment']),
                            'name' => strip_tags($_POST['name'])))
                );
            }
        } else {
            throw new Zend_Controller_Action_Exception('Страница не найдена 404', 404);
        }
    }

}

